import 'package:flutter/material.dart';
import 'package:photo_view/photo_view.dart';
import 'package:photo_view/photo_view_gallery.dart';

var listData = const [
  "https://www.itying.com/images/flutter/1.png",
  "https://www.itying.com/images/flutter/2.png",
  "https://www.itying.com/images/flutter/3.png",
  "https://www.itying.com/images/flutter/4.png",
  "https://www.itying.com/images/flutter/5.png",
  "https://www.itying.com/images/flutter/6.png",
];

class HeroPage extends StatefulWidget {

  final Map arguments;

  const HeroPage({super.key,required this.arguments});

  @override
  State<HeroPage> createState() => _HeroPageState();
}

class _HeroPageState extends State<HeroPage> {

  late List listData = [];
  late int initialPage = 0;

  @override
  void initState() {
    super.initState();
    listData = widget.arguments["listData"];
    initialPage = widget.arguments["initialPage"];
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: (){
        Navigator.pop(context);
      },
      child: Hero(
        tag: widget.arguments["imageUrl"],
        child: Scaffold(
          backgroundColor: Colors.black,
          body: Center(
            child: AspectRatio(
              aspectRatio: 16/9,
              /*//预览单张图片
              child: PhotoView(
                imageProvider:NetworkImage(widget.arguments["imageUrl"],)
              ),*/

              child: PhotoViewGallery.builder(
                itemCount: listData.length,
                pageController: PageController(initialPage: initialPage ),
                onPageChanged: (index) {
                  print(index);
                },
                builder: (context,index){
                  return PhotoViewGalleryPageOptions(imageProvider: NetworkImage(listData[index]));
                }
              ),
            ),
          ),
        ),
      )
    );
  }
}
